package es.ats.codington.web.servlets;

import java.io.IOException;
import java.util.ArrayList;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import es.ats.codington.festival.domain.Event;
import es.ats.codington.festival.services.EventSingUpService;

/**
 * Servlet implementation class ListEventServlet.
 */
@WebServlet("/ListEventServlet")
public class ListEventServlet extends HttpServlet {
	
	/** The Constant serialVersionUID. */
	private static final long serialVersionUID = 1L;
       
    /**
     * Instantiates a new list event servlet.
     *
     * @see HttpServlet#HttpServlet()
     */
    public ListEventServlet() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * Do get.
	 *
	 * @param request the request
	 * @param response the response
	 * @throws ServletException the servlet exception
	 * @throws IOException Signals that an I/O exception has occurred.
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		 HttpSession session = request.getSession(true);
	   	 int idV =(Integer) session.getAttribute("VisitorID");
		 try{		
				/**
				 * Your Events
				 */
				
				/* Prueba */
				EventSingUpService ev = new EventSingUpService();				
				ArrayList<Event> event = new ArrayList<Event>();
				boolean result = ev.visitorInEvent(idV, event);
				
				/**
				 * All Events
				 */
				EventSingUpService ev2 = new EventSingUpService();					
				ArrayList<Event> event2 = new ArrayList<Event>();
				boolean result2 = ev.obtainSemiAllEvents(idV, event2);
				
				
					session.setAttribute("YourEvents", event);	
					session.setAttribute("SemiAllEvents", event2);
	    /*    	 RequestDispatcher rd=request.getRequestDispatcher("listEventVisitor.jsp");  
	             rd.include(request,response);*/
	             
	             response.sendRedirect("listEventVisitor.jsp");
				//Tener en cuenta si tiene algun array vacio
				


				
				
				
				
			
			
	    }catch(Exception theException){
	        System.out.println(theException); 
	   }
			
		
	}

	/**
	 * Do post.
	 *
	 * @param request the request
	 * @param response the response
	 * @throws ServletException the servlet exception
	 * @throws IOException Signals that an I/O exception has occurred.
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
	


		
	}
	
	/**
	 * Send list eventvisitor.
	 *
	 * @param request the request
	 * @param response the response
	 */
	public void sendListEventvisitor(HttpServletRequest request, HttpServletResponse response){
   	 HttpSession session = request.getSession(true);
   	 int idV =(Integer) session.getAttribute("VisitorID");

		System.out.println(idV);
		try{		
			/**
			 * Your Events
			 */
			
			/* Prueba */
			EventSingUpService ev = new EventSingUpService();				
			ArrayList<Event> event = new ArrayList<Event>();
			boolean result = ev.visitorInEvent(idV, event);
			
			/**
			 * All Events
			 */
			EventSingUpService ev2 = new EventSingUpService();					
			ArrayList<Event> event2 = new ArrayList<Event>();
			boolean result2 = ev.obtainSemiAllEvents(idV, event2);			
			
			session.setAttribute("YourEvents", event);	
			session.setAttribute("SemiAllEvents", event2);
			
			/*RequestDispatcher rd=request.getRequestDispatcher("listEventVisitor.jsp");  
            rd.include(request,response);*/
             
             response.sendRedirect("listEventVisitor.jsp");
			//Tener en cuenta si tiene algun array vacio
		
    }catch(Exception theException){
        System.out.println(theException); 
    }	
	}
}
